<?php
$id_category = (isset($this->pageValues['id_category'])) ? $this->pageValues['id_category'] : '';
echo $this->menuBuilder($this->menus, $id_category);
?>
<div class="orange_line" >&nbsp;</div>
<?php echo $this->form_search;?>
<div class="left_col">
    <?php echo $this->partial("index/_orderControl.phtml", array('control_active' => 'orders_history'));?>

    <?php if (!empty($this->msg_add_cart)):?>
        <div class="msg_order_panel">
            <p><?php echo $this->translate($this->msg_add_cart)?></p>
        </div>
    <?php endif;?>  

    <div class="order_detail">
        <h2 class="order_subject"><?php echo sprintf($this->translate('ORDER_ID_NUMBER'), $this->escape($this->cart->id));?></h2>
        <p class="sender_info">
            <?php 
                if(!empty($this->cart->link)):
                    echo sprintf($this->translate('BUYER_NAME'), '<a target="_blank" href="' . $this->escape($this->cart->link) . '">' . $this->escape($this->cart->user_name) . '</a>');
                else:
                    echo sprintf($this->translate('BUYER_NAME'), '<span>' . $this->escape($this->cart->user_name) . '</span>');
                endif;
            ?>
        </p>
        <p class="sender_info"><?php echo sprintf($this->translate('BUYER_EMAIL'), '<span>' . $this->escape($this->cart->user_email) . '</span>'); ?></p>
        <p class="sender_info"><?php echo sprintf($this->translate('BUYER_PHONE'), '<span>' . $this->escape($this->cart->user_phone). '</span>'); ?></p>
        <p class="sender_info"><?php echo sprintf($this->translate('BUYER_LOCATION'), '<span>' . $this->escape($this->cart->user_location). '</span>'); ?></p>
        <p class="sender_info"><?php echo sprintf($this->translate('BUYER_TIME'), '<span>' . date($this->translate("FORMAT_DATE"), $this->cart->time_sent). '</span>'); ?></p>
        
    </div>
    <table class="tbl_cart_products" id="tbl_cart_products">
    <thead>
        <tr>
            <th>
                <span class="tbl_item_name">
                    <?php echo $this->translate('CART_ITEM_NAME') ?>
                </span>
            </th>
            <th>
                <span class="tbl_quantity">
                    <?php echo $this->translate('CART_ITEM_QUANTITY') ?>
                </span>
            </th>
            <th>
                <span class="tbl_payment">
                    <?php echo $this->translate('CART_ITEM_SUB_TOTAL') ?>
                </span>
            </th>
        </tr>
    </thead>
    <tbody>
        <?php
            if(count($this->list_products)):
                $total = 0;
                foreach ($this->list_products as $key => $product):		
                    if($product->cart_price != null):
                        $total += $product->cart_price * $product->quantity;
                    endif;
        ?>
        <tr class="cart_product_row">
            <td>
                <div class="product_cover">
                    <a  href="<?php echo $this->pageUrl(array('target' => 'detail','id' => $product['id_store'], 'id_product' => $product['id'])); ?>">
                        <img alt="thumbnail" src="<?php echo UPLOAD_URL . '/product/thumbnail/' . $product->image;?>">
                    </a>
                </div>
                <div class="product_info">
                    <p class="product_name">
                        <a  href="<?php echo $this->pageUrl(array('target' => 'detail','id' => $product['id_store'], 'id_product' => $product['id'])); ?>">
                            <?php echo $this->escape($product['name']) ?>
                        </a>
                    </p>
                    <?php if(!empty($product['sku'])):?>
                    <p class="product_SKU">
                        <label><?php echo $this->translate('SKU'); ?>:</label>
                        <span><?php echo $this->escape($product['sku']);?></span>
                    </p>
                    <?php endif; ?>
                    <p class="price_info">
                        <?php if($product->cart_price != null):?>
                        <span class="price">
                            <?php echo Core_Util::formatPrice($this->store->unit_code, $product->cart_price);?>
                        </span>
                        <span><?php echo $this->store->getCurrency()?></span>
                        <?php else:?>
                            <span class="price"><?php echo "N/A"?></span>
                        <?php endif;?>
                    </p>
                </div>
            </td>
            <td>
                <p style="text-align: right;">
                    <span><?php echo $product['quantity']; ?></span>
                </p>
            </td>
            <td>            
                <p class="payment">
                    <?php if($product->cart_price != null):?>
                        <span class="price">
                            <?php echo Core_Util::formatPrice($this->store->unit_code, $product->cart_price * $product->quantity);?>
                        </span>
                        <span><?php echo $this->store->getCurrency()?></span>
                    <?php else:?>
                        <span><?php echo "N/A"?></span>
                    <?php endif;?>
                </p>
            </td>
        </tr>
        <?php 
                endforeach;
        ?>
        <tr class="end_row">
            <td colspan="2" class="td_total">
                <span><?php echo $this->translate('TOTAL');?></span>
            </td>
            <td class="total_payment">
                <span class="total_price">
                    <?php echo Core_Util::formatPrice($this->store->unit_code, $total);?>
                </span>
                <span><?php echo $this->store->getCurrency()?></span>
            </td>
        </tr>
        <?php else: ?>
        <tr id="empty_cart_row">
            <td colspan="4" class="empty_cart">
                <?php echo $this->translate('MSG_EMPTY_ORDER_PRODUCT');?>
            </td>
        </tr>
        <?php endif;?>
    </tbody>
    </table>
    <?php if(!empty($this->cart->user_note)):?>
    <p class="sender_info">
        <?php echo sprintf($this->translate('BUYER_NOTE'), '<span class="">' . nl2br($this->escape($this->cart->user_note)) . '</span>'); ?>
    </p>
    <?php endif;?>
</div>
<div class="right_col">
    <?php echo $this->partial("index/_purchaseInstruction.phtml", array(
        'store' => $this->store
    ));?>
    
    <?php echo $this->partial("index/_recentViewedProducts.phtml", array(
        'social' => $this->social,
        'rv_products' => $this->rv_products,
        'store' => $this->store
    ));?>
</div>

<?php echo $this->partial('index/scrollTop.phtml');?>